#include "head.h"
#include "train.h"
#include "SendMsg.h"
#include "transfile.h"
#include "login.h"
#include "cmdtype.h"

int main(int argc, char *argv[])
{
	// 0. 创建套接字
	int clientfd = socket(AF_INET, SOCK_STREAM, 0);
	ERROR_CHECK(clientfd, -1, "socket");

	printf("sizeof(struct sockaddr):%ld\n", sizeof(struct sockaddr));
	printf("sizeof(struct sockaddr_in):%ld\n", sizeof(struct sockaddr_in));

	// 1. 设置服务器的网络地址
	struct sockaddr_in serverAddr;
	memset(&serverAddr, 0, sizeof(serverAddr));

	serverAddr.sin_family = AF_INET;
	serverAddr.sin_port = htons(8888);
	serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");

	int ret = connect(clientfd, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
	ERROR_CHECK(ret, -1, "connect");

	loginInServer(clientfd);

	printf("conn has connected\n");
	while (getchar() != '\n')//读取一行剩余的字符（丢掉）（包括换行符）
		;
	analyze_cmd(clientfd);
	close(clientfd);
}
